var KtkzCfgl = function() {
	var tableColum = [ {
		title : '仓房名称',
		field : 'housename',
		align : 'center',
		valign : 'middle',
	}, {
		title : '运行状态',
		field : 'allstatus',
		align : 'center',
		valign : 'middle',
	}, {
		title : '运行模式',
		field : 'runmode',
		align : 'center',
		valign : 'middle',
	}, {
		title : '开始时间',
		field : 'begintime',
		align : 'center',
		valign : 'middle',
	}, {
		title : '结束时间',
		field : 'endtime',
		align : 'center',
		valign : 'middle',
	}, {
		title : '最高粮温',
		field : 'highttemp',
		align : 'center',
		valign : 'middle',
	}, {
		title : '最低粮温',
		field : 'lowertemp',
		align : 'center',
		valign : 'middle',
	}, {
		title : '平均粮温',
		field : 'avgtemp',
		align : 'center',
		valign : 'middle',
	}, {
		title : '仓内温度',
		field : 'inttemp',
		align : 'center',
		valign : 'middle',
	}, {
		title : '仓内湿度',
		field : 'inhumidity',
		align : 'center',
		valign : 'middle',
	}, {
		title : '仓外温度',
		field : 'outtemp',
		align : 'center',
		valign : 'middle',
	}, {
		title : '仓外湿度',
		field : 'outhumidity',
		align : 'center',
		valign : 'middle',
	}, {
		title : '能耗',
		field : 'power',
		align : 'center',
		valign : 'middle',
	}, {
		title : '操作',
		field : 'cz',
		align : 'center',
		valign : 'middle',
		formatter : function(value, row, index) {
			return '<a href="javascript:KtkzCfgl.openDetail(\'' + row.storehousecode + '\');" class="btn btn-success">详情</a>';
		}
	} ];

	var initPingpu = function() {
		$
			.ajax({
				type : "GET",
				cache : false,
				url : "ktkz/GLlist?orgcode=" + orgcode,
				success : function(responseJson) {
					if (responseJson.success == true) { // 返回true
						var data = responseJson.obj;
						if (data.length > 0) {
							$("#pingpuKtkzView").empty();
							$
								.each(
									data,
									function(n, value) {
										var div = "<div class=\"col-lg-3 col-md-3 col-sm-6 col-xs-12 default-view"
											+ value.housename + "\">";
										div = div
											+ "<div class=\"dashboard-stat dashboard-stat-v2 default widhei\">";
										div = div
											+ "<div class=\"visual\"><img src=\"assets/global/img/picture/small.png\" /><div>&nbsp;&nbsp;"
											+ value.housename + "</div></div>";
										div = div + "<div class=\"details\"><div class=\"number\"></div>";
										div = div + "<table class=\"desc\">";
										div = div + "<tr><td>制冷状态：</td><td>" + value.allstatus
											+ "</td></tr>";
										div = div + "<tr><td>制冷时长：</td><td>" + value.durationtime
											+ "</td></tr>";
										div = div + "<tr><td>外温：</td><td>" + value.outtemp + "</td></tr>";
										div = div + "<tr><td>仓温：</td><td>" + value.inttemp + "℃</td></tr>";
										div = div + "<tr><td>粮温：</td><td>" + value.avgtemp + "℃</td></tr>";
										div = div + "</table>";
										div = div + "</div>";
										div = div
											+ "<div style=\"margin-top: 160px;text-align:center;clear:both; margin-bottom: 10px; font-weight: 500;\">启动时间："
											+ value.begintime + "</div></div></div>";
										$("#pingpuKtkzView").append($(div));
										$(".default-view" + value.housename).on("click", function() {
											openDetail(value.storehousecode);
										});
									});
						}
					} else {
						QTYYComponents.bootstrapSweetAlert("", responseJson.msg, "error");
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					QTYYComponents.bootstrapSweetAlert("", "查询失败!!!", "error");
				}
			});
	}

	var openDetail = function(id) {
		QTYYComponents.layerOpen("仓房详情", '1200px', '680px', "ktkz/cfxq/main?id=" + id);
	}

	var initLiebiao = function() {
		QTYYComponentsTable.initBootStrapTable($("#ktkzTable"), "/ktkz/LBlist", tableColum);
	}

	/**
	 * 绑定按钮事件
	 */
	var eventHandler = function() {
		$("#liebiaoBtn").on("click", function() {
			$("#pingpuKtkzView").css("display", "none");
			$("#liebiaoKtkzView").css("display", "block");
		});
		$("#pingpuBtn").on("click", function() {
			$("#pingpuKtkzView").css("display", "block");
			$("#liebiaoKtkzView").css("display", "none");
		});
		$("#searchBtn").on("click", function() {
			QTYYComponentsTable.searchTable("ktkzTable", "searchForm");
		});
	}

	return {
		init : function() {
			QTYYComponents.initSelect("", "cwfs");
			QTYYComponents.initSelect("/dict/cangfang", "cangfang");
			QTYYComponents.initDateRange("jcsj");
			eventHandler();
			initPingpu();
			initLiebiao();
		},
		openDetail : function(id) {
			openDetail(id);
		}
	}
}();

jQuery(document).ready(function() {
	KtkzCfgl.init();
});